// vim: sw=4:ts=4:nu:nospell:fdc=4
/**
 * Simple Message Bus Example
 *
 * @author    Ing. Jozef Sakáloš
 * @copyright (c) 2009, by Ing. Jozef Sakáloš
 * @date      19. September 2008
 * @version   $Id: simplebus.js 156 2009-09-19 23:31:02Z jozo $
 *
 * @license simplebus.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. Commercial use is permitted to the extent that the 
 * code/component(s) do NOT become part of another Open Source or Commercially
 * licensed development library or toolkit without explicit permission.
 * 
 * License details: http://www.gnu.org/licenses/lgpl.html
 */
 
/*global Ext,Example */
Ext.ns('Example');
 
Ext.BLANK_IMAGE_URL = 'ext3/resources/images/default/s.gif';

// message bus simulation
Example.Bus = new Ext.util.Observable();
Example.Bus.addEvents('message');

// panel that sends and receives bus messages
Example.Panel = Ext.extend(Ext.Panel, {
	 autoScroll:true
	,bodyStyle:'font-size:12px'
	,initComponent:function() {
		var config = {
			bbar:{
				 itemId:'bbar'
				,items:[{
					 xtype:'button'
					,text:'Clear'
					,scope:this
					,handler:function() {
						this.body.update('');
					}
				}
				,'->'
				,{
					 xtype:'label'
					,text:'Message: '
				},{
					 xtype:'textfield'	
					,itemId:'msgtext'

				},{
					 xtype:'button'
					,text:'Send'
					,scope:this
					,handler:function() {
						var textField = this.getBottomToolbar().getComponent('msgtext');
						Example.Bus.fireEvent('message', textField.getValue());
					}
				}]
			}
		}; // eo config
		Ext.apply(this, Ext.apply(this.initialConfig, config));
		Example.Panel.superclass.initComponent.apply(this, arguments);
	}
	,onRender:function() {
		Example.Panel.superclass.onRender.apply(this, arguments);
		Example.Bus.on('message', this.onMessage, this);
	}
	,onMessage:function(message) {
		this.body.createChild({html:message});
	}

}); // eo class Example.Panel

// app entry point
Ext.onReady(function() {

	var c1 = new Example.Panel({
		 title:'Subscriber | Publisher 1'
		,renderTo:Ext.getBody()
		,id:'c1'
		,width:300
		,height:150
	});

	var c2 = new Example.Panel({
		 title:'Subscriber | Publisher 2'
		,renderTo:Ext.getBody()
		,id:'c2'
		,width:300
		,height:150
	});

	var c3 = new Example.Panel({
		 title:'Subscriber | Publisher 3'
		,renderTo:Ext.getBody()
		,id:'c3'
		,width:300
		,height:150
	});

}); // eo onReady
 
// eof
